package cc.rengu.igas.cops.core.service.base;

import cc.rengu.igas.cops.common.constant.CopsTreeNodeConstant;
import cc.rengu.igas.cops.common.enums.RespCodeEnum;
import cc.rengu.igas.share.common.constant.ShareTreeNodeConstant;
import cc.rengu.igas.share.common.constant.TransCacheConstant;
import cc.rengu.igas.share.common.constant.UserSessionConstant;
import cc.rengu.igas.share.core.model.CouponDetailBean;
import cc.rengu.igas.share.core.model.MchntInfo;
import cc.rengu.igas.share.core.model.OrderDetail;
import cc.rengu.igas.share.core.model.PlatMchntInfo;
import cc.rengu.igas.share.core.realize.MchntService;
import cc.rengu.igas.share.core.realize.PublicService;
import cc.rengu.igas.share.core.realize.UserService;
import cc.rengu.igas.share.core.realize.impl.MchntServiceImpl;
import cc.rengu.igas.share.core.realize.impl.PublicServiceImpl;
import cc.rengu.igas.share.core.realize.impl.RiskMonitorServiceImpl;
import cc.rengu.igas.share.core.realize.impl.UserServiceImpl;
import cc.rengu.oltp.service.base.BizBaseService;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.service.common.constant.TreeNodeConstant;
import cc.rengu.oltp.service.common.dao.MchntOrderInfoMapper;
import cc.rengu.oltp.service.common.dao.PayOrderInfoMapper;
import cc.rengu.oltp.service.common.dao.UserOrderInfoMapper;
import cc.rengu.oltp.service.common.dao.impl.MchntOrderInfoMapperImpl;
import cc.rengu.oltp.service.common.dao.impl.PayOrderInfoMapperImpl;
import cc.rengu.oltp.service.common.dao.impl.UserOrderInfoMapperImpl;
import cc.rengu.oltp.service.common.entity.MchntOrderInfo;
import cc.rengu.oltp.service.common.entity.PayOrderInfo;
import cc.rengu.oltp.service.common.entity.UserOrderInfo;
import cc.rengu.oltp.service.common.enums.*;
import cc.rengu.oltp.service.model.BizException;
import cc.rengu.oltp.service.model.BizResponse;
import cc.rengu.oltp.service.model.OrderInfo;
import cc.rengu.oltp.service.model.RiskMonitorInfo;
import cc.rengu.oltp.service.realize.OrderService;
import cc.rengu.oltp.service.realize.RiskMonitorService;
import cc.rengu.oltp.service.realize.impl.OrderServiceImpl;
import cc.rengu.oltp.utility.annotation.BIZ_AFTER;
import cc.rengu.oltp.utility.annotation.BIZ_BEFORE;
import cc.rengu.oltp.utility.annotation.BIZ_PROCESS;
import cc.rengu.oltp.utility.util.*;

import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
 * 支付退货服务基类
 * 检查验签、商户号是否一致、商户状态
 * 判断用户订单是否存在及用户订单是否满足退款要求(订单未完成、订单交易状态非成功、业务状态不是完成/部分退款/确认收货、存在正在退款的用户订单、
 * 商户订单不存在或商户订单有实时清算的商户、累计退款金额超过用户订单的交易金额)
 * 关于有商城营销的退款:商户累计退款订单金额-商户累计退款订单中订单优惠金额<=原用户订单的待支付金额
 * refundType-部分退款/全额退款
 * transJoinMomp-原交易是否参与营销
 * orderAllRefundFlag-订单全额退款标识
 * curTotalRefundAmt-当前已退款金额
 *
 * @author 王成
 * @version 1.0
 * @date 2018/4/17.
 */
public abstract class RefundService extends BizBaseService {
    public PlatMchntInfo platMchntInfo = null;
    public MchntInfo mchntInfo = null;

    @Override
    protected Object beforeBizProcess() throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String instId = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.INST_ID);
        String msgSrcId = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.MSG_SRC_ID);
        String transAmt = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.ORDER_AMT);
        /*默认部分退款*/
        xmlTreeUtil.setXmlTreeStringValue(ShareTreeNodeConstant.REFUND_TYPE, AppParamConstant.NO);
        /*原交易参与营销标识*/
        xmlTreeUtil.setXmlTreeStringValue(ShareTreeNodeConstant.ORDER_JOIN_MOMP, AppParamConstant.NO);
        /*订单是否全部退款*/
        xmlTreeUtil.setXmlTreeStringValue(ShareTreeNodeConstant.ORDER_ALL_REFUND_FLAG, AppParamConstant.NO);
        /*原交易参与营销标识*/
        boolean isOrderMomp = false;
        /*订单是否全部退款*/
        boolean isOrderAllRefund = false;

        /* Step1：查找BIZ_BEFORE的注解*/
        invokeBizAnnoMethod(BIZ_BEFORE.class);

        /* Step2：检查验签状态 */
        String verifySignFlag = xmlTreeUtil.getXmlTreeStringValue(CopsTreeNodeConstant.VERIFY_SIGN_FLAG);
        if (AppParamConstant.NO.equals(verifySignFlag)) {
            throw new BizException(RespCodeEnum.VERIFY_SIGN_ERROR.getRespCode(), RespCodeEnum.VERIFY_SIGN_ERROR.getRespDesc());
        }

        /* Step3：检查接口合法性(使用退款的公共交易码进行校验) */
        PublicService publicService = new PublicServiceImpl();
        publicService.checkInputValidity(msgSrcId, "P04CP000");
        publicService.checkInputParamLegal();

        /* Step4：检查平台商户合法性 */
        MchntService mchntService = new MchntServiceImpl();
        String platMchntNo = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.PLAT_MCHNT_NO);
        if (!StringUtil.isEmptyOrNull(platMchntNo)) {
            if (mchntService.checkPlatMchntStatus(instId, platMchntNo)) {
                rglog.error("平台商户<{}>状态异常!", platMchntNo);
                throw new BizException(RespCodeEnum.MCHNT_STATUS_ABNORMAL.getRespCode(), RespCodeEnum.MCHNT_STATUS_ABNORMAL.getRespDesc());
            }
            platMchntInfo = mchntService.getPlatMchntInfo(instId, platMchntNo);
            if (null == platMchntInfo) {
                rglog.error("查询平台商户基本信息失败<{}>", platMchntNo);
                throw new BizException(RespCodeEnum.MCHNT_INFO_NOT_FOUND.getRespCode(), RespCodeEnum.MCHNT_INFO_NOT_FOUND.getRespDesc());
            }
        }

        /* Step5：检查商户合法性 */
        String mchntNo = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.MCHNT_NO);
        if (!StringUtil.isEmptyOrNull(mchntNo)) {
            UserService userService = new UserServiceImpl();
            String transMchntNo = userService.getUserSessionValue(UserSessionConstant.PLAT_MCHNT_NO);
            if (!StringUtil.isEmptyOrNull(transMchntNo) && !mchntNo.equals(transMchntNo)) {
                rglog.error("交易请求上送的商户<{}>与用户会话中商户号<{}>不一致!", mchntNo, transMchntNo);
                throw new BizException(RespCodeEnum.MCHNT_DISACCORD.getRespCode(), RespCodeEnum.MCHNT_DISACCORD.getRespDesc());
            }
            if (!mchntService.checkMchntStatus(instId, mchntNo)) {
                rglog.error("商户<{}>状态异常!", mchntNo);
                throw new BizException(RespCodeEnum.MCHNT_STATUS_ABNORMAL.getRespCode(), RespCodeEnum.MCHNT_STATUS_ABNORMAL.getRespDesc());
            }
            mchntInfo = mchntService.getMchntInfo(instId, mchntNo);
            if (null == mchntInfo) {
                rglog.error("查询商户基本信息失败<{}>", mchntNo);
                throw new BizException(RespCodeEnum.MCHNT_INFO_NOT_FOUND.getRespCode(), RespCodeEnum.MCHNT_INFO_NOT_FOUND.getRespDesc());
            }
        }

        /* Step6:原支付订单校验 */
        OrderService orderService = new OrderServiceImpl();
        String origUserOrderId = xmlTreeUtil.getXmlTreeStringValue(CopsTreeNodeConstant.ORIG_USER_ORDER_ID);
        OrderInfo origOrderInfo = (OrderInfo) GlobalTransUtil.getCacheValue(TransCacheConstant.ORIG_ORDER_INFO);
        if (null == origOrderInfo) {
            origOrderInfo = orderService.selectOrderInfoByUserOrderId(instId, origUserOrderId);
            if (null == origOrderInfo) {
                rglog.info("用户支付订单不存在!");
                throw new BizException(RespCodeEnum.ORDER_NOEXIT.getRespCode(), RespCodeEnum.ORDER_NOEXIT.getRespDesc());
            }
            PayOrderInfoMapper payOrderInfoMapper = new PayOrderInfoMapperImpl();
            List<PayOrderInfo> payOrderInfoList = payOrderInfoMapper.selectPayOrderInfoBySysSeqNum(instId, origOrderInfo.getUserOrderInfo().getSysSeqNum());
            origOrderInfo.setPayOrderInfoList(payOrderInfoList);
            GlobalTransUtil.setCacheValue(TransCacheConstant.ORIG_ORDER_INFO, origOrderInfo);
        }
        if (!OrderStatusEnum.FINISH.getStatus().equals(origOrderInfo.getUserOrderInfo().getOrderStatus())) {
            rglog.warn("订单状态<{}>,非成功<03>，不允许退款", origOrderInfo.getUserOrderInfo().getOrderStatus());
            throw new BizException(RespCodeEnum.ORDER_CANT_REFUND.getRespCode(), RespCodeEnum.ORDER_CANT_REFUND.getRespDesc());
        }
        if (!TransStatusEnum.TRANS_SUCC.getStatus().equals(origOrderInfo.getUserOrderInfo().getTransStatus())) {
            rglog.error("订单交易状态<{}>,非成功<1>，不允许退款", origOrderInfo.getUserOrderInfo().getTransStatus());
            throw new BizException(RespCodeEnum.ORDER_CANT_REFUND.getRespCode(), RespCodeEnum.ORDER_CANT_REFUND.getRespDesc());
        }
        if (!BizStatusEnum.FINISH.getStatus().equals(origOrderInfo.getUserOrderInfo().getBizStatus()) &&
                !BizStatusEnum.PART_REFUND.getStatus().equals(origOrderInfo.getUserOrderInfo().getBizStatus()) &&
                !BizStatusEnum.CONFIRM.getStatus().equals(origOrderInfo.getUserOrderInfo().getBizStatus()) &&
                !BizStatusEnum.NOT_CONFIRM_PART_REFUND.getStatus().equals(origOrderInfo.getUserOrderInfo().getBizStatus())) {
            rglog.warn("业务状态<{}>,非完成<00>或部分退款<31>或未确认收货部分退货<33>或确认收货<50>，不允许退款", origOrderInfo.getUserOrderInfo().getBizStatus());
            throw new BizException(RespCodeEnum.ORDER_CANT_REFUND.getRespCode(), RespCodeEnum.ORDER_CANT_REFUND.getRespDesc());
        }

        /* Step6.1:根据原系统流水号查询退款订单，判断是否存在退款中的订单,如果存在退款中的拒绝当前退款 */
        UserOrderInfoMapper userOrderInfoMapper = new UserOrderInfoMapperImpl();
        List<UserOrderInfo> userOrderInfoList = userOrderInfoMapper.selectUserOrderInfoByOrigSysSeqNum(instId, origOrderInfo.getUserOrderInfo().getSysSeqNum());
        if (userOrderInfoList != null && userOrderInfoList.size() > 0) {
            Predicate<UserOrderInfo> transStat = p -> TransStatusEnum.TRANS_TIMEOUT.getStatus().equals(p.getTransStatus());
            Predicate<UserOrderInfo> bizStat = p -> BizStatusEnum.PROCESSING.getStatus().equals(p.getBizStatus());
            userOrderInfoList = userOrderInfoList.stream().filter(transStat.or(bizStat)).collect(Collectors.toList());
            if (userOrderInfoList.size() > 0) {
                rglog.error("原用户订单号<{}>、系统流水号<{}>存在退款状态未确定，不允许退款", origUserOrderId, userOrderInfoList.get(0).getSysSeqNum());
                throw new BizException(RespCodeEnum.ORDER_CANT_REFUND.getRespCode(), RespCodeEnum.ORDER_CANT_REFUND.getRespDesc());
            }
        }

        /* Step6.2:获取原商户订单,校验商户订单列表中的订单是否允许退款 */
        List<MchntOrderInfo> mchntOrderInfoList = origOrderInfo.getMchntOrderInfoList();
        if (mchntOrderInfoList == null || mchntOrderInfoList.size() == 0) {
            rglog.error("商户订单信息表中无该笔订单,instId:<{}>,sysSeqNum:<{}>.", instId, origOrderInfo.getUserOrderInfo().getSysSeqNum());
            throw new BizException(RespCodeEnum.ORDER_CANT_REFUND.getRespCode(), RespCodeEnum.ORDER_CANT_REFUND.getRespDesc());
        }
        if (mchntOrderInfoList.stream().anyMatch(item -> item.getRealSettleFlag().equals(AppParamConstant.YES))) {
            rglog.error("当前订单属于D0实时入账订单，不支持DO退款!");
            throw new BizException(RespCodeEnum.ORDER_CANT_REFUND.getRespCode(), RespCodeEnum.ORDER_CANT_REFUND.getRespDesc());
        }
        List<MchntOrderInfo> mchntOrderInfoListMchntFilter = origOrderInfo.getMchntOrderInfoList();
        if (!StringUtil.isEmptyOrNull(mchntNo)) {
            rglog.info("正在进行单个商户<{}>的退款！", mchntNo);
            mchntOrderInfoListMchntFilter = mchntOrderInfoList.stream().filter(item -> item.getMchntNo().equals(mchntNo)).collect(Collectors.toList());
            if (!mchntOrderInfoListMchntFilter.isEmpty()) {
                String mchntRefundAmt = AmountUtil.addition(transAmt, mchntOrderInfoListMchntFilter.get(0).getRefundAmt());
                if (AmountUtil.compare(mchntRefundAmt, mchntOrderInfoListMchntFilter.get(0).getOrderAmt()) == 1) {
                    rglog.info("本商户累计退款金额:<{}>大于商户订单金额:<{}>", mchntRefundAmt, mchntOrderInfoListMchntFilter.get(0).getOrderAmt());
                    throw new BizException(RespCodeEnum.OPM_OVER_AMT_LIMIT.getRespCode(), RespCodeEnum.OPM_OVER_AMT_LIMIT.getRespDesc());
                }
            }
        } else {
            rglog.info("未上送退款商户号<{}>，默认为全订单退款！", mchntNo);
        }

        /* Step6.3:累计订单已退款金额,并判断当前退款金额是否允许退款 */
        String totalRefundAmt = "0.00";
        for (MchntOrderInfo mchntOrderInfo : mchntOrderInfoList) {
            if (mchntOrderInfo.getRefundAmt() != null) {
                totalRefundAmt = AmountUtil.addition(totalRefundAmt, mchntOrderInfo.getRefundAmt());
            }
            if (AmountUtil.compare(mchntOrderInfo.getCustomerMarketAmt(), "0") == 1) {
                //用户参与营销
                isOrderMomp = true;
            }
        }
        rglog.debug("当前订单已累计产生的退款金额:<{}>", totalRefundAmt);
        /* Step6.3.1:获取累计退款订单中的累计订单优惠金额 */
        String totalRefundDiscountAmt = "0.00";
        MchntOrderInfoMapper mchntOrderInfoMapper = new MchntOrderInfoMapperImpl();
        List<MchntOrderInfo> refundedMchntOrderInfos = mchntOrderInfoMapper.selectMchntOrderInfoByOrigSysSeqNum(instId, origOrderInfo.getUserOrderInfo().getSysSeqNum());
        if (null != refundedMchntOrderInfos && !refundedMchntOrderInfos.isEmpty()) {
            refundedMchntOrderInfos = refundedMchntOrderInfos.stream().filter(item -> !TransStatusEnum.SYSTEM_REJECT.getStatus().equals(item.getTransStatus())
                    && !TransTypeEnum.CONFIRM.equals(TransTypeEnum.getTransType(item.getTxnNum()))).collect(Collectors.toList());
            if (!refundedMchntOrderInfos.isEmpty()) {
                for (MchntOrderInfo refundedMchntOrder : refundedMchntOrderInfos) {
                    totalRefundDiscountAmt = AmountUtil.addition(totalRefundDiscountAmt, refundedMchntOrder.getOrderDiscountAmt());
                }
            }
        }
        CouponDetailBean couponDetailBean = new CouponDetailBean();
        ConvertUtil.convertOutput(couponDetailBean);
        if (null != couponDetailBean.getRefundOrderDetailList() && !couponDetailBean.getRefundOrderDetailList().isEmpty()) {
            for (OrderDetail orderDetail : couponDetailBean.getRefundOrderDetailList()) {
                totalRefundDiscountAmt = AmountUtil.addition(totalRefundDiscountAmt, orderDetail.getOrderDiscountAmt());
            }
        }
        rglog.debug("已产生的商户退款订单中累计订单优惠金额+本地订单优惠金额:<{}>", totalRefundDiscountAmt);
        if (AmountUtil.compare(AmountUtil.addition(transAmt, totalRefundAmt), origOrderInfo.getUserOrderInfo().getOrderAmt()) == 1) {
            rglog.info("本次退款金额:<{}>加累计退款金额:<{}>大于用户订单金额:<{}>", transAmt, totalRefundAmt, origOrderInfo.getUserOrderInfo().getOrderAmt());
            throw new BizException(RespCodeEnum.OPM_OVER_AMT_LIMIT.getRespCode(), RespCodeEnum.OPM_OVER_AMT_LIMIT.getRespDesc());
        } else if (AmountUtil.compare(transAmt, origOrderInfo.getUserOrderInfo().getOrderAmt()) == 0) {
            rglog.info("用户订单金额与当前退款金额一致，全额退款");
            isOrderAllRefund = true;
            xmlTreeUtil.setXmlTreeStringValue(ShareTreeNodeConstant.ORDER_ALL_REFUND_FLAG, AppParamConstant.YES);
            xmlTreeUtil.setXmlTreeStringValue(ShareTreeNodeConstant.REFUND_TYPE, AppParamConstant.YES);
        } else if (AmountUtil.compare(origOrderInfo.getUserOrderInfo().getOrderAmt(), AmountUtil.addition(transAmt, totalRefundAmt)) == 0) {
            rglog.info("用户订单金额:<{}>等于累计退款金额:<{}>,设置为全额退款状态!", origOrderInfo.getUserOrderInfo().getOrderAmt(), AmountUtil.addition(transAmt, totalRefundAmt));
            xmlTreeUtil.setXmlTreeStringValue(ShareTreeNodeConstant.REFUND_TYPE, AppParamConstant.YES);
        }
        if (AmountUtil.compare(totalRefundDiscountAmt, AmountUtil.subtraction(origOrderInfo.getUserOrderInfo().getOrderAmt(), origOrderInfo.getUserOrderInfo().getNeedPayAmt())) == 1) {
            rglog.info("当前累计订单优惠金额:<{}>大于原订单商城优惠金额:<{}>.", totalRefundDiscountAmt, AmountUtil.subtraction(origOrderInfo.getUserOrderInfo().getOrderAmt(), origOrderInfo.getUserOrderInfo().getNeedPayAmt()));
            throw new BizException(RespCodeEnum.OPM_OVER_AMT_LIMIT.getRespCode(), RespCodeEnum.OPM_OVER_AMT_LIMIT.getRespDesc());
        }
        if (AmountUtil.compare(origOrderInfo.getUserOrderInfo().getNeedPayAmt(), AmountUtil.subtraction(AmountUtil.addition(transAmt, totalRefundAmt), totalRefundDiscountAmt)) == -1) {
            rglog.error("累计退款金额+本次退款金额-累计退款金额中订单优惠金额>原用户订单用户待支付金额,本次退款金额<{}>,已退款金额<{}>,商户累计退款订单中订单优惠金额:<{}>,原交易用户待支付金额<{}>.累计退款金额超限",
                    transAmt, totalRefundAmt, refundedMchntOrderInfos, origOrderInfo.getUserOrderInfo().getNeedPayAmt());
            throw new BizException(RespCodeEnum.OPM_OVER_AMT_LIMIT.getRespCode(), RespCodeEnum.OPM_OVER_AMT_LIMIT.getRespDesc());
        }

        /* Step6.3.2:判断是否有营销 */
        List<PayOrderInfo> payOrderInfoList = origOrderInfo.getPayOrderInfoList();
        if (payOrderInfoList != null && !payOrderInfoList.isEmpty()) {
            payOrderInfoList = payOrderInfoList.stream().filter(item -> ChannelEnum.MOMP.getChannelType().equals(item.getMsgDstId()) && TransTypeEnum.PAY.equals(TransTypeEnum.getTransType(item.getDstTxnNum()))).collect(Collectors.toList());
            if (!payOrderInfoList.isEmpty()) {
                if (0 != AmountUtil.compare("0.00", payOrderInfoList.get(0).getChannelDiscountAmt())) {
                    rglog.debug("营销订单有对客营销.<{}>", payOrderInfoList.get(0).getChannelDiscountAmt());
                    isOrderMomp = true;
                    xmlTreeUtil.setXmlTreeStringValue(ShareTreeNodeConstant.ORDER_JOIN_MOMP, AppParamConstant.YES);
                }
            }
        }

        /* Step6.3.3:判断用户是否参与了营销，参与营销必须全额退款 */
        rglog.debug("用户当前交易退款金额:<{}>", transAmt);
        if (isOrderMomp) {
            if (!isOrderAllRefund) {
                rglog.warn("用户订单<{}>参与了营销优惠，必须订单全额退货.本次退款金额<{}>,用户订单金额<{}>", origUserOrderId, transAmt, origOrderInfo.getUserOrderInfo().getOrderAmt());
                throw new BizException(RespCodeEnum.ORDER_CANT_REFUND.getRespCode(), RespCodeEnum.ORDER_CANT_REFUND.getRespDesc());
            }
            rglog.info("原交易参与营销，需要调用营销退款接口");
            xmlTreeUtil.setXmlTreeStringValue(ShareTreeNodeConstant.ORDER_JOIN_MOMP, AppParamConstant.YES);
            /* 全订单退款标志 */
            xmlTreeUtil.setXmlTreeStringValue(ShareTreeNodeConstant.ORDER_ALL_REFUND_FLAG, AppParamConstant.YES);
            xmlTreeUtil.setXmlTreeStringValue(ShareTreeNodeConstant.REFUND_TYPE, AppParamConstant.YES);
        }

        /* Step7：将原交易信息设置到内部树 */
        GlobalTransUtil.setCacheValue(TransCacheConstant.ORIG_ORDER_INFO, origOrderInfo);
        GlobalTransUtil.setCacheValue(TransCacheConstant.ORIG_USER_ORDER_INFO, origOrderInfo.getUserOrderInfo());
        GlobalTransUtil.setCacheValue(TransCacheConstant.ORIG_MCHNT_ORDER_INFO_LIST, mchntOrderInfoListMchntFilter);
        //当期完成退款的金额
        xmlTreeUtil.setXmlTreeStringValue(ShareTreeNodeConstant.CURRENT_TOTAL_REFUND_AMT, totalRefundAmt);

        /* Step8：交易处理前客户化 */
        rglog.info("交易处理前客户化");
        return bizBeforeCust();
    }

    @Override
    protected BizResponse callBizService(Object request) throws Exception {
        /* Step1：公共业务处理 */

        /* Step2：查找BIZ_PROCESS的注解 */
        invokeBizAnnoMethod(BIZ_PROCESS.class);

        /* Step3：业务逻辑处理*/
        return bizProcessCust(request);
    }

    @Override
    protected void afterBizProcess(BizResponse response) throws Exception {
        /* Step1：业务调用后公共处理*/

        /* Step2：查找BIZ_AFTER的注解 */
        invokeBizAnnoMethod(BIZ_AFTER.class);

        /* Step3：业务调用后客户化处理 */
        bizAfterCust(response);
    }

    @Override
    protected RiskMonitorInfo getRiskMonitorInfo() {
        RiskMonitorInfo riskMonitorInfo = new RiskMonitorInfo();
        RiskMonitorService riskMonitorService = new RiskMonitorServiceImpl();
        riskMonitorInfo.setTransMonitor(riskMonitorService);
        return riskMonitorInfo;
    }

    /**
     * 业务处理前客户化处理
     *
     * @return 业务处理实体类
     */
    protected abstract Object bizBeforeCust() throws Exception;

    /**
     * 业务逻辑处理客户化处理
     *
     * @param request 业务处理前的返回实体类
     * @return 业务处理结果
     */
    protected abstract BizResponse bizProcessCust(Object request) throws Exception;

    /**
     * 业务处理后逻辑处理
     *
     * @param response 业务调用响应信息
     */
    protected abstract void bizAfterCust(Object response) throws Exception;
}
